package com.roc.web.action.merinfo;

/**
 * @author zbl
 * @date 2014-08-09
 * 
 * */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.log4j.Logger;
import org.apache.poi.hdgf.streams.Stream;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.roc.bean.JsonBean;
import com.roc.bean.MerinfoDetail;
import com.roc.bean.MerinfoSearchBean;
import com.roc.bean.TermBean;
import com.roc.bean.orgMainBean;
import com.roc.newPage.IPageService;
import com.roc.page.BaseSearchCondition;
import com.roc.page.PaginationBaseAction;
import com.roc.pojo.AuditingItem;
import com.roc.pojo.EsmidinfoMerinfo;
import com.roc.pojo.EsmidinfoTmp;
import com.roc.pojo.Operators;
import com.roc.pojo.OrgBean;
import com.roc.pojo.TReceive;
import com.roc.pojo.TblDictionaryLayerItem;
import com.roc.pojo.TblEditMchtBizFee;
import com.roc.pojo.TblEditMchtExtendInfo;
import com.roc.pojo.TblEditMchtInf;
import com.roc.pojo.TblEditMchtPicture;
import com.roc.pojo.TblInsInf;
import com.roc.pojo.Termapply;
import com.roc.service.IAgentService;
import com.roc.service.IMerchantServices;
import com.roc.service.IMerinfoImageService;
import com.roc.service.IPagenitionService;
import com.roc.service.ITerminalService;
import com.roc.service.IUserService;
import com.roc.service.IorgService;
import com.roc.service.ServiceException;
import com.roc.service.operator.IPowerInfoService;
import com.roc.util.Constance;
import com.roc.util.ExcelUtil;
import com.roc.util.Utils;
import com.roc.util.constant.AuditingResultCodeType;
import com.roc.util.constant.ConfigMerinfoUtil;
import com.roc.util.constant.ConfigProperties;
import com.roc.util.constant.Constant;
import com.roc.util.constant.MerchantStatus;
import com.roc.util.constant.MerinfoReturninfo;
import com.roc.util.constant.MerinfoStatus;
import com.roc.util.constant.RejectReason;
import com.roc.util.constant.RejectType;
import com.roc.util.constant.Role;
import com.roc.util.httpZip.HttpFileToZipUtil;


@Component
@Namespace("/mer")
@SuppressWarnings("all")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class merinfoAction extends PaginationBaseAction {
	static Logger logger = Logger.getLogger(merinfoAction.class);

	@Autowired
	IPowerInfoService iPowerInfoService;
	
	@Autowired
	IorgService orgService;
	@Autowired
	IMerchantServices merinfoService;
	@Autowired
	IPagenitionService pagenitionService;
	@Autowired
	IPageService pageService;
	@Autowired
	ITerminalService terminalService;
	@Autowired
	IPowerInfoService powerInfoService;
	@Autowired
	IAgentService agentService;
	@Autowired
	IUserService userService;
	@Autowired
	IMerinfoImageService merinfoImageService;
	
	private InputStream zipFile;
	private String  zipName;
	private Termapply termapply;
	private List<TermBean> termBeanList;

	private EsmidinfoMerinfo merDetail;// 商户附件详情

	private TblEditMchtInf merinfo; // 商户临时表
	private String provice32;//省份32域名
	private String city32;//城市32域
	private String isDetail; // 查看详情
	private MerinfoSearchCondtion searchCondition;//
	private MerinfoDetail merinfoDetail; // 商户详情
	private AuditingItem auditing;// 审核意见
	private String[] transTypes;// 交易类型
	private List<OrgBean> orgList = new ArrayList<OrgBean>();
	private List<String> initCheckBoxList = new ArrayList<String>();
	private String merInfoIdList;
	private File excelFile;
	private String dealType; //0 冻结 1解冻 2 注销
	private String rejectType;
	private String accountNo;
	private String result;
	private List<String> rejectReasons;
	
	private String reasons;
	
	private Double zwPayRate;
	
	private String mchtRejectType;	//区分商户驳回完善 1普通商户 2风控 3直营商户 
	
	private String saveMerinfoFlag; //暂时商户信息类别 1暂存
	
	private String merCardName; //证件名称
	
	private String merCardId; //证件号码
	
	private String verifyFlag; //验证类型
	
	private boolean verifyInfo;
	
	public String getReasons() {
		return reasons;
	}

	public void setReasons(String reasons) {
		this.reasons = reasons;
	}
	
	//查询发展人
	@Action(value="getDlpOpertorsByAccountNo")
	public void getDlpOpertorsByAccountNo()
	{
		HttpServletResponse response=ServletActionContext.getResponse();
		response.setContentType("text/json;charset=UTF-8");
		try {
			Operators operators=merinfoService.getOpertorsByAccountNo(accountNo);
			Map<String, Object> mapList=new HashMap<String,Object>();
			String code="fail";
			Object message="发展人账号对应发展人不存在";
			if(operators!=null)
			{
				code="success";
				message=operators.getId();
			}
			 mapList.put("code",code);
			 mapList.put("message",message);
			result=JSONObject.fromObject(mapList).toString();
			response.getWriter().print(result);
		} catch (Exception e) {
			logger.info(e.getMessage(),e);
		} 
	}
	
	/**
	 * 验证身份证合法性
	 */
	@Action(value="checkIdentityInfo")
	public void checkIdentityInfo(){
		try {
			HttpServletResponse response=ServletActionContext.getResponse();
			response.setContentType("text/json;charset=UTF-8");
			verifyInfo = merinfoService.validateIdInfo(merCardName, merCardId, verifyFlag);
			response.getWriter().print(verifyInfo);
		} catch (ServiceException e) {
			logger.error("验证身份证信息失败！", e);
		} catch (IOException e) {
			logger.info(e.getMessage(),e);
		}
	}

	/**
	 * 初始化进件页面
	 * */
	@Action(value = "addMerJsp", results = { @Result(name = "success", location = "/pages/merinfo/addMerinfoNew.jsp"),
			@Result(name = "error", location = "/error.jsp") })
	public String addMerJsp() {
		Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		Map developPersonMap= new HashMap();
		List orgList = new ArrayList();
		try {
			init(true);
			merinfo=new TblEditMchtInf();
			String groupCd = op.getGroupCd();
				if(Constant.STR_NUMBER_ONE.equals(groupCd)){
					getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getDirectProductList(ConfigMerinfoUtil.DIRECT_FUNCTION_ALL, false));//获取开通直连产品信息
					getRequest().setAttribute("product", ConfigMerinfoUtil.getDirectProductTypeList()); //直连商户开通产品类型
				}else{
					getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getPosFunction(ConfigMerinfoUtil.ALL_FUNCTION, false));//开通产品信息
					getRequest().setAttribute("product", ConfigMerinfoUtil.getProductListNew());//开通产品信息
				}
			getRequest().setAttribute("isMid", Constance.isMid());//临时商户号
			getRequest().setAttribute("provinesMap", ConfigProperties.getUnionProviceProperties());//32域省份
		} catch (Exception e) {
			logger.error("加载商户基本信息出错", e);
			addActionError("加载商户基本信息出错");
		}
		return SUCCESS;
	}
	
	

	// 添加商户信息
	@Action(value = "addMerinfo", results = { @Result(name = SUCCESS, type = "chain", location = "addMerJsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String addMerinfos() {
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
			try {
				String returninfo ="";
				if(Constant.STR_NUMBER_ONE.equals(saveMerinfoFlag)){
					returninfo = merinfoService.saveMerinfo(merinfo, op);	//商户信息暂存
				}else{
					if(merinfo.getProductCode()==null || merinfo.getProductCode().length<1){//未选择产品
						addActionMessage("产品信息未选择"); return SUCCESS;
					}
					if(merinfo.getProductCode().length==1 && (merinfo.getProductCode()[0]=="1171" || merinfo.getProductCode()[0]=="1271")){//只选择t0
						addActionMessage("产品信息T+1必选"); return SUCCESS;
					}
					/*if(merinfo.getUcBccd()==null || merinfo.getUcBccd().equals("0") || merinfo.getUcBccd().equals("")){
						if(city32==null || city32.equals("0") || city32.equals("")){
							merinfo.setUcBccd(provice32);//省市
						}else{
							merinfo.setUcBccd(city32);//城镇
						}
					}*/
					if(merinfo.getUcBccd()==null || merinfo.getUcBccd().equals("0") || merinfo.getUcBccd().equals("")){
						merinfo.setUcBccd(provice32);//省市
					}
					returninfo = merinfoService.insertMerinfo(merinfo, op);
				}
				addActionMessage(returninfo);
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				addActionError(e.getMessage());
				return ERROR;
			}
		return SUCCESS;
	}
	
	/*********************************************** 进件查询（待审核） *******************************************************/
	 
	@Action(value = "queryMerinfoStatusForOne", 
			results = { @Result(name = SUCCESS, location = "/pages/merinfo/merinfoStatusOne.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String queryMerinfoStatusForOne() {
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		
		try {
			if (searchCondition == null) {
				searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
				if (searchCondition == null) {
					searchCondition = new MerinfoSearchCondtion();
				}
			}
			if( op.getRoleType().equals(Role.RISK_CONTROL_LEAD.getCode())||op.getRoleType().equals(Role.RISK_CONTROL_OPERATORS.getCode())){
	            searchCondition.setOrgCode(op.getOrgCode());//当前查询人员所属机构
	            searchCondition.setRoleId(op.getRoleType());// 角色
	            searchCondition.setOpId(String.valueOf(op.getId()));//当前人员id
	            searchCondition.setRkopId(String.valueOf(op.getId()));// 角色
			}else{
				Map<String, String> map=iPowerInfoService.queryRealIdByOpId(op.getSuperiorId(), op.getRoleType(), op.getId(), op.getOrgCode());
	            String orgCode=map.get("orgCode");
	            String superRole= map.get("superRole");
	            String opRealId =map.get("opRealId");
	            searchCondition.setGroupCd(map.get("groupCd"));
	            searchCondition.setOrgCode(orgCode);//当前查询人员所属机构
	            searchCondition.setRoleId(superRole);// 角色
	            searchCondition.setOpId(opRealId);//当前人员id
	            searchCondition.setRkopId(opRealId);// 角色
	            searchCondition.setOneOrgCode(op.getOneagentid());//机构号
			}
			searchCondition.setStatus("99");
			//querySon(op);
			handleResultList(op);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
		 
			return SUCCESS;
		 
	}
	
	/**
	 * 间连直营待审核商户查询
	 * @return JC
	 */
	@Action(value = "querySirectMerinfo", 
			results = { @Result(name = SUCCESS, location = "/pages/merinfo/merinfoStatusFour.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String querySirectMerinfo() {
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		
		try {
			if (searchCondition == null) {
				searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
				if (searchCondition == null) {
					searchCondition = new MerinfoSearchCondtion();
				}
			}
			   if(searchCondition.getMerinfoFlag()==0){
				   searchCondition.setMerinfoFlag(98);//默认查询
			   }
				Map<String, String> map=iPowerInfoService.queryRealIdByOpId(op.getSuperiorId(), op.getRoleType(), op.getId(), op.getOrgCode());
	            String orgCode=map.get("orgCode");
	            String superRole= map.get("superRole");
	            String opRealId =map.get("opRealId");
	            searchCondition.setGroupCd("2");
	            searchCondition.setOrgCode(orgCode);//当前查询人员所属机构
	            searchCondition.setRoleId(superRole);// 角色
	            searchCondition.setOpId(opRealId);//当前人员id
	            searchCondition.setRkopId(opRealId);// 角色
	            searchCondition.setOneOrgCode(op.getOneagentid());//机构号
			//querySon(op);
			handleResultList(op);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
		 
			return SUCCESS;
		 
	}
	
	
	// 商户(审核)查询初始化
		@Action(value = "merinfoOneListInit", results = {	
				@Result(name =SUCCESS, location = "/pages/merinfo/merinfoStatusTwo.jsp"),
				@Result(name = ERROR, location = "/error.jsp") })
		public String merinfoListInit() {
			try {
				 return SUCCESS;
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				e.printStackTrace();
				addActionError(e.getMessage());
				return ERROR;
			}

		}

		// 商户(审核)查询
		@Action(value = "queryMerinfoStatusForTwo", results = {
				@Result(name = SUCCESS, location = "/pages/merinfo/merinfoStatusTwo.jsp"),
				@Result(name = ERROR, location = "/error.jsp") })
		public String queryMerinfoList() {
			Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
			if(op.getRoleType().equals(Role.AGENT.getCode()) && !op.getAccountNo().equals("sdsyb")){
				 addActionError("无权限访问");
				 return ERROR;
			 }
			try {
				if (searchCondition == null) {
					searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
					if (searchCondition == null) {
						searchCondition = new MerinfoSearchCondtion();
					}
				}
				
				if(op.getRoleType().equals(Role.RISK_CONTROL_LEAD.getCode()) || 
				   op.getRoleType().equals(Role.RISK_CONTROL_OPERATORS.getCode())  ){
					searchCondition.setOrgCode(op.getOrgCode());//当前查询人员所属机构
					searchCondition.setStatus(MerinfoStatus.S_5.getCode());//审核查询
					searchCondition.setRkopId(String.valueOf(op.getId()));//操作员id
					searchCondition.setRoleId(op.getRoleType());//角色
					searchCondition.setMerinfoFlag(3);
					searchCondition.setOneOrgCode(null);//机构号
					
					handleResultList(op);
				}else{
					addActionError("无此权限");
					return SUCCESS;
				}
				if(op.getAccountNo().equals("cj") && op.getRoleType().equals(Role.RISK_CONTROL_LEAD.getCode())){
					boolean is=userService.isCheckMerinfo();
					if(is){
						getRequest().setAttribute("cj", "0");
					}else{
						getRequest().setAttribute("cj", "1");
					}
				}
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				addActionError(e.getMessage());
				return ERROR;
			}
				return SUCCESS;
		}
	
		/*********************************************** 商户审核详情页面 *******************************************************/
		// 审核页面
		@Action(value = "checkMerinfoinfo", results = { 
				@Result(name = SUCCESS, location = "/pages/merinfo/checkMerinfoTwo.jsp"),
			    @Result(name =INPUT, type = "chain", location = "queryMerinfoStatusForTwo"),
				@Result(name = ERROR, location = "/error.jsp") })
		public String checkMerchantTwoJsp() {
			Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
			 if(op.getRoleType().equals(Role.AGENT.getCode()) && !op.getAccountNo().equals("sdsyb")){
				 addActionError("无权限访问");
				 return ERROR;
			 }
			try {
				if (null==merinfo || merinfo.getId() == null || merinfo.getId().equals("")) {
					addActionError("异常，审核商户信息失败");
					return ERROR;
				}
				//开启批量审核判断
				/*boolean is=userService.isCheckMerinfo();
				if(is){
					addActionMessage(MerinfoReturninfo.S_35.getName());
					return INPUT;
				}*/
				//商户信息回显
				merinfo=merinfoService.queryMerinfoTmpInfo(merinfo.getId(),true,true,true);
				String[] productCodeFlag=merinfoService.queryMchtBizDealArray(merinfo.getId(), false, false);
				getRequest().setAttribute("mcc", ConfigProperties.getHyMccTypeProperties());//mcc
				logger.info("------"+ConfigProperties.getUnionProviceProperties().size()+"------");
				getRequest().setAttribute("provinesMap", ConfigProperties.getUnionProviceProperties());//32域省份
				getRequest().setAttribute("auditingMap",ConfigMerinfoUtil.getAuditingMap());//审核
				getRequest().setAttribute("rejectTypeList",Arrays.asList(RejectType.values()));
				//查询32域信息
				String code32=userService.queryAreaDetailBy32Code(merinfo.getUcBccd());
				getRequest().setAttribute("code32",code32);
				//所属代理商
				String orgName = "";
				String ext1 = merinfo.getExt1();
				if(ext1 != null && ext1.length() > 0){
					Operators opr = powerInfoService.loadOperatorsById(Long.valueOf(ext1));
					orgName = opr.getRealName();
				}
				getRequest().setAttribute("orgName", orgName);
				//getRequest().setAttribute("choosePosName",ConfigProperties.getSysDB1("PROD_CD",true).get(merinfo.getProductCode()));
				//getRequest().setAttribute("choosePosFunction", ConfigMerinfoUtil.getPosFunction(merinfo.getProductCode(), false));//进件默认选中产品信息
				
				if(Constant.STR_NUMBER_ONE.equals(merinfo.getGroupCD()) && (Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T1) ||
						Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T0))){
					getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getDirectProductList(ConfigMerinfoUtil.DIRECT_FUNCTION_ALL, true));//获取开通直连产品信息
				}else{
					getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getPosFunction(ConfigMerinfoUtil.ALL_FUNCTION, true));//开通产品信息
				}
				getRequest().setAttribute("roleType", op.getRoleType());
				getRequest().setAttribute("groupCd", merinfo.getGroupCD());
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				addActionError(e.getMessage());
				return ERROR;
			}
			return SUCCESS;
		}

		/**
		 * 审核操作
		 * */
		@Action(value = "checkNewMerinfo", 
				results = { @Result(name =SUCCESS, type = "chain", location = "queryMerinfoStatusForTwo"),
				@Result(name = ERROR, location = "/error.jsp") })
		public String checkMerchantTwo() {
			try {
				Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
				 if(op.getRoleType().equals(Role.AGENT.getCode()) && !op.getAccountNo().equals("sdsyb")){
					 addActionError("无权限访问");
					 return ERROR;
				 }
				if (merinfo == null || "".equals(Constance.Null2EmptyTrim(merinfo.getId()))) {
					addActionError("商户号为空，审核出错啦！");
					return ERROR;
				}
				/*if(merinfo.getUcBccd()==null || merinfo.getUcBccd().equals("0") || merinfo.getUcBccd().equals("")){
					if(city32==null || city32.equals("0") || city32.equals("")){
						merinfo.setUcBccd(provice32);//省市
					}else{
						merinfo.setUcBccd(city32);//城镇
					}
				}*/
				String isCheck=merinfoService.checkMerinfo( op,merinfo);
				String[] splitResult=isCheck.split("_");
				addActionMessage(splitResult[0]);
				/*if(splitResult.length>1){//发送短信
					userService.addMessageSend(splitResult[1], splitResult[2]);
				}*/
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				addActionError(e.getMessage());
				return ERROR;
			}
			return SUCCESS;
		}
		
		/**
		 * 加载驳回原因
		 */
		@Action(value = "loadRejectReason")
		public void loadRejectReason(){
			PrintWriter printWriter = null;
			JSONObject json = new JSONObject();
			try {
				getResponse().setCharacterEncoding("utf-8");
				printWriter = getResponse().getWriter();
				List<String> rejectReasons = RejectType.valueOf(rejectType).gets();
				json.put("rejectReasons", rejectReasons);
				printWriter.write(json.toString());
			} catch (Exception e) {
				logger.error("加载驳回原因异常");
				logger.error(e.getMessage(),e);
			}finally{
				if(printWriter != null){
					printWriter.close();
				}
			}
		}
		
		/**
		 * 批量审核开关
		 * 
		 * */
		@Action(value = "checkSomeMerinfo", 
				results = { @Result(name =SUCCESS, type = "chain", location = "queryMerinfoStatusForTwo"),
				@Result(name = ERROR, location = "/error.jsp") })
		public String checkSomeMerchant() {
			PrintWriter pw = null;
			try {
				Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
				getResponse().setCharacterEncoding("utf-8");
				pw = getResponse().getWriter();
				String isTrue=userService.editOperStatus();
				if(isTrue.split("_").length>1){
					if(isTrue.split("_")[0].equals("1")){
						pw.write("1");
					}else{
						pw.write("0");
					}
				}else{
					pw.write("2");
				}
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
			}finally{
				if(pw != null){
					pw.close();
				}
			}
			return SUCCESS;
		}
	/**
	 * 驳回商户信息完善查询
	 * */
	@Action(value = "merinfoinfoComplete", results = {	
			@Result(name =SUCCESS, location = "/pages/merinfo/merinfoStatusThree.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String merinfoinfoComplete() {
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		try {
			if (searchCondition == null) {
				searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
				if (searchCondition == null) {
					searchCondition = new MerinfoSearchCondtion();
				}
			}
			//运营角色转换
			Map<String, String> map=iPowerInfoService.queryRealIdByOpId(op.getSuperiorId(), op.getRoleType(), op.getId(), op.getOrgCode());
            String orgCode=map.get("orgCode");
            String superRole= map.get("superRole");
            String opRealId =map.get("opRealId");
           	searchCondition.setOrgCode(orgCode);//当前查询人员所属机构
            searchCondition.setRoleId(superRole);// 角色
            searchCondition.setOpId(opRealId);//当前人员id
            searchCondition.setMerinfoFlag(0);
			searchCondition.setStatus(MerinfoStatus.S_4.getCode());//驳回
			if(!"".equals(op.getOneagentid())){
				searchCondition.setOneOrgCode(op.getOneagentid());//机构号
			}
			//querySon(op);
			handleResultList(op);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
			return SUCCESS;
	}
		
	/**
	 * 驳回初始化进件页面
	 * */
	@Action(value = "addMerCompleteJsp", 
			results = { @Result(name = SUCCESS, location = "/pages/merinfo/addMerinfoComplete.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String addMerCompleteJsp() {
		try {
			 if(null != mchtRejectType){
				merinfo=merinfoService.queryMerinfoTmpInfo(merinfo.getId(), false,true,true);
				initComplete(merinfo);
			 }else{
				init(true);
				merinfo=merinfoService.queryMerinfoTmpInfo(merinfo.getId(), false,true,true);
			}
			merinfo.setNationCd(merinfo.getNationCd().trim());
			List<TblEditMchtBizFee> fees = merinfo.getFee();
			for(TblEditMchtBizFee fee : fees){
				if(fee != null){
					if(fee.getProdCd() != null && ConfigMerinfoUtil.ZWPAY_FUNCTION.equals(fee.getProdCd())){
						zwPayRate = fee.getMchtFeePercent();
					}
				}
			}
			if(merinfo.getMchtExtendInfo() != null){
				//身份证有效期长期与否判断
				if((merinfo.getMchtExtendInfo().getCertifStartDate()==null || merinfo.getMchtExtendInfo().getCertifStartDate()=="") 
						&& (merinfo.getMchtExtendInfo().getCertifEndDate()==null || merinfo.getMchtExtendInfo().getCertifEndDate()=="")){
					merinfo.getMchtExtendInfo().setCertifValidity("0");
				}else{
					merinfo.getMchtExtendInfo().setCertifValidity("1");
				}
				//营业执照有效期长期与否判断
				if((merinfo.getMchtExtendInfo().getBusiLiceStartDate()==null || merinfo.getMchtExtendInfo().getBusiLiceStartDate()=="") 
						&& (merinfo.getMchtExtendInfo().getBusiLiceEndDate()==null || merinfo.getMchtExtendInfo().getBusiLiceEndDate()=="")){
					merinfo.getMchtExtendInfo().setBusiLiceValidity("0");
				}else{
					merinfo.getMchtExtendInfo().setBusiLiceValidity("1");
				}
			}
			if(null!=merinfo.getUpMccCd()){
				getRequest().setAttribute("mccReq", ConfigMerinfoUtil.getMccByKey(merinfo.getUpMccCd()));//mcc名称
			}
				getRequest().setAttribute("provinesMap", ConfigProperties.getUnionProviceProperties());//32域省份
			if(Constant.STR_NUMBER_ONE.equals(merinfo.getGroupCD())){
				getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getDirectProductList(ConfigMerinfoUtil.DIRECT_FUNCTION_ALL, false));//获取开通直连产品信息
				getRequest().setAttribute("product", ConfigMerinfoUtil.getDirectProductTypeList()); //直连商户开通产品类型
			}else{
				getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getPosFunction(ConfigMerinfoUtil.ALL_FUNCTION, false));//开通产品信息
				getRequest().setAttribute("product", ConfigMerinfoUtil.getProductListNew());//开通产品信息
			}
			String areaProvinceCode = merinfoService.getInstalledProvince(merinfo.getUcBccd());
			String areaCityCode = merinfoService.getInstalledCity(merinfo.getUcBccd());
			getRequest().setAttribute("areaProvinceCode", areaProvinceCode);
			getRequest().setAttribute("areaCityCode", areaCityCode);
			provice32 = areaProvinceCode;
		} catch (Exception e) {
			logger.error("加载商户基本信息出错", e);
			addActionError("加载商户基本信息出错");
		}
		return SUCCESS;
	}
	
	
	/**
	 * 驳回进件提交
	 * */
	@Action(value = "editMerComplete", 
			results = { @Result(name =SUCCESS, type = "chain", location = "merinfoinfoComplete"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String editMerComplete() {
		 
		try {
			Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);//当前操作员
			//简单校验
			if(merinfo.getProductCode()==null || merinfo.getProductCode().length<1){//未选择产品
				addActionMessage("产品信息未选择"); return SUCCESS;
			}
			if(merinfo.getProductCode().length==1 && (merinfo.getProductCode()[0]=="1171" || merinfo.getProductCode()[0]=="1271")){//只选择t0
				addActionMessage("产品信息T+1必选"); return SUCCESS;
			}
			/*if(merinfo.getUcBccd()==null || merinfo.getUcBccd().equals("0") || merinfo.getUcBccd().equals("")){
				if(city32==null || city32.equals("0") || city32.equals("")){
					merinfo.setUcBccd(provice32);//省市
				}else{
					merinfo.setUcBccd(city32);//城镇
				}
			}*/
			if(merinfo.getUcBccd()==null || merinfo.getUcBccd().equals("0") || merinfo.getUcBccd().equals("")){
					merinfo.setUcBccd(provice32);//省市
			}
			TblEditMchtInf editMchtInf = merinfoService.getTblEditMchtInfByMerId(merinfo.getId());
			if(editMchtInf != null){
				String merStatus = editMchtInf.getStatus();
				if(merStatus.length()<0 || !"04".equals(merStatus)){
					addActionMessage("商户当前状态不是驳回状态，完善商户信息失败！"); return SUCCESS;
				}
			}else{
				addActionMessage("查询临时商户状态失败！"); return SUCCESS;
			}
			mchtRejectType = "1";
			String returnInfo=merinfoService.editMerinfo(merinfo, op, mchtRejectType);
			addActionMessage(returnInfo);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	
	/**
	 * 直营驳回商户查询
	 * @return
	 */
	@Action(value = "directMerRejectList", results = {	
			@Result(name =SUCCESS, location = "/pages/merinfo/directMerRejectList.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String directMerRejectList(){
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		try {
			if (searchCondition == null) {
				searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
				if (searchCondition == null) {
					searchCondition = new MerinfoSearchCondtion();
				}
			}
			//运营角色转换
			Map<String, String> map=iPowerInfoService.queryRealIdByOpId(op.getSuperiorId(), op.getRoleType(), op.getId(), op.getOrgCode());
            String orgCode=map.get("orgCode");
            String superRole= map.get("superRole");
            String opRealId =map.get("opRealId");
           	searchCondition.setOrgCode(orgCode);//当前查询人员所属机构
            searchCondition.setRoleId(superRole);// 角色
            searchCondition.setOpId(opRealId);//当前人员id
            searchCondition.setMerinfoFlag(0);
			searchCondition.setStatus(MerinfoStatus.S_15.getCode());//驳回
			if(!"".equals(op.getOneagentid())){
				searchCondition.setOneOrgCode(op.getOneagentid());//机构号
			}
			handleResultList(op);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * 直营商户驳回完善初始化页面
	 * @return
	 */
	@Action(value = "directMerRejComplete", 
			results = { @Result(name = SUCCESS, location = "/pages/merinfo/directMerRejComplete.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String directMerRejComplete(){
		try {
			 if(null != mchtRejectType){
				merinfo=merinfoService.queryMerinfoTmpInfo(merinfo.getId(), false,false,true);
				initComplete(merinfo);
			 }else{
				init(true);
				merinfo=merinfoService.queryMerinfoTmpInfo(merinfo.getId(), false,false,true);
			}
			merinfo.setNationCd(merinfo.getNationCd().trim());
			List<TblEditMchtBizFee> fees = merinfo.getFee();
			for(TblEditMchtBizFee fee : fees){
				if(fee != null){
					if(fee.getProdCd() != null && ConfigMerinfoUtil.ZWPAY_FUNCTION.equals(fee.getProdCd())){
						zwPayRate = fee.getMchtFeePercent();
					}
				}
			}
			if(merinfo.getMchtExtendInfo() != null){
				//身份证有效期长期与否判断
				if((merinfo.getMchtExtendInfo().getCertifStartDate()==null || merinfo.getMchtExtendInfo().getCertifStartDate()=="") 
						&& (merinfo.getMchtExtendInfo().getCertifEndDate()==null || merinfo.getMchtExtendInfo().getCertifEndDate()=="")){
					merinfo.getMchtExtendInfo().setCertifValidity("0");
				}else{
					merinfo.getMchtExtendInfo().setCertifValidity("1");
				}
				//营业执照有效期长期与否判断
				if((merinfo.getMchtExtendInfo().getBusiLiceStartDate()==null || merinfo.getMchtExtendInfo().getBusiLiceStartDate()=="") 
						&& (merinfo.getMchtExtendInfo().getBusiLiceEndDate()==null || merinfo.getMchtExtendInfo().getBusiLiceEndDate()=="")){
					merinfo.getMchtExtendInfo().setBusiLiceValidity("0");
				}else{
					merinfo.getMchtExtendInfo().setBusiLiceValidity("1");
				}
			}
			if(null!=merinfo.getUpMccCd()){
				getRequest().setAttribute("mccReq", ConfigMerinfoUtil.getMccByKey(merinfo.getUpMccCd()));//mcc名称
			}
				getRequest().setAttribute("provinesMap", ConfigProperties.getUnionProviceProperties());//32域省份
			if(Constant.STR_NUMBER_ONE.equals(merinfo.getGroupCD())){
				getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getDirectProductList(ConfigMerinfoUtil.DIRECT_FUNCTION_ALL, false));//获取开通直连产品信息
				getRequest().setAttribute("product", ConfigMerinfoUtil.getDirectProductTypeList()); //直连商户开通产品类型
			}else{
				getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getPosFunction(ConfigMerinfoUtil.ALL_FUNCTION, false));//开通产品信息
				getRequest().setAttribute("product", ConfigMerinfoUtil.getProductListNew());//开通产品信息
			}
			String areaProvinceCode = merinfoService.getInstalledProvince(merinfo.getUcBccd());
			String areaCityCode = merinfoService.getInstalledCity(merinfo.getUcBccd());
			getRequest().setAttribute("areaProvinceCode", areaProvinceCode);
			getRequest().setAttribute("areaCityCode", areaCityCode);
			provice32 = areaProvinceCode;
		} catch (Exception e) {
			logger.error("加载商户基本信息出错", e);
			addActionError("加载商户基本信息出错");
		}
		return SUCCESS;
	}
	
	 @Action(value = "editDirectMerComplete", 
		results = { @Result(name =SUCCESS, type = "chain", location = "directMerRejectList"),
		@Result(name = ERROR, location = "/error.jsp") })
	public String editDirectMerComplete(){
		try {
			Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);//当前操作员
				if(merinfo.getProductCode()==null || merinfo.getProductCode().length<1){//未选择产品
					addActionMessage("产品信息未选择"); return SUCCESS;
				}
				if(merinfo.getProductCode().length==1 && (merinfo.getProductCode()[0]=="1171" || merinfo.getProductCode()[0]=="1271")){//只选择t0
					addActionMessage("产品信息T+1必选"); return SUCCESS;
				}
				if(merinfo.getUcBccd()==null || merinfo.getUcBccd().equals("0") || merinfo.getUcBccd().equals("")){
					merinfo.setUcBccd(provice32);//省市
				}
				TblEditMchtInf editMchtInf = merinfoService.getTblEditMchtInfByMerId(merinfo.getId());
				if(editMchtInf != null){
					String merStatus = editMchtInf.getStatus();
				if(merStatus.length()<0 || !"15".equals(merStatus)){
					addActionMessage("商户当前状态不是驳回状态，完善商户信息失败！"); return SUCCESS;
					}
				}else{
					addActionMessage("查询临时商户状态失败！"); return SUCCESS;
				}
				mchtRejectType = "3";
				String returnInfo=merinfoService.editMerinfo(merinfo, op, mchtRejectType);
				addActionMessage(returnInfo);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	
	
	/**
	 * 跳转领件页面
	 * */
	@Action(value="loadCollarPiecesJsp",results={@Result(name=SUCCESS,location="/pages/merinfo/collarPieces.jsp"),
			@Result(name = "error", location = "/error.jsp")})
	public String returnCollarPiecesJsp(){
		try {
			Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
			 if(op.getRoleType().equals(Role.AGENT.getCode()) && !op.getAccountNo().equals("sdsyb")){
				 addActionError("无权限访问");
				 return ERROR;
			 }
		} catch (Exception e) {
			logger.error("跳转到领件页面出错");
		}
		return SUCCESS;
	}
	
	/**
	 * 风控领件
	 * @return
	 */
	@Action(value="queryCollarPiecesJsp",results={@Result(name=SUCCESS,location="/pages/merinfo/collarPieces.jsp"),
			@Result(name = ERROR, location = "/error.jsp")})
	public String checkCollarPieces(){

		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		if(op.getRoleType().equals(Role.AGENT.getCode()) && !op.getAccountNo().equals("sdsyb")){
			 addActionError("无权限访问");
			 return ERROR;
		 }
		try {
			if(!op.getRoleType().equals(Role.RISK_CONTROL_OPERATORS.getCode()) &&
					   !op.getRoleType().equals(Role.RISK_CONTROL_LEAD.getCode())	){
					addActionError("无此权限");
						return SUCCESS;
			}
			//判断是否开启自动审核，若开启自动审核，则不能领取间连、对私、并且普通mcc
			boolean isTrue=userService.isCheckMerinfo();
			if(null !=searchCondition.getRiskGetMerType() && isTrue && searchCondition.getRiskGetMerType().equals("4")){//开启自动审核领取 间连、对私、并且普通mcc
				addActionMessage("自动审核已开启，不能领取[间联/普通MCC/结算账户对私]类型的商户!");
				return SUCCESS;
			}
			if (searchCondition == null) {
				searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
				if (searchCondition == null) {
					searchCondition = new MerinfoSearchCondtion();
				}
			}
			searchCondition.setOrgCode(op.getOrgCode());//当前查询人员所属机构
			searchCondition.setStatus(MerinfoStatus.S_1.getCode());//等待领件
			searchCondition.setRoleId(op.getRoleType());// 角色
			searchCondition.setOpId(String.valueOf(op.getId()));//当前人员id
			searchCondition.setOneOrgCode(null);//机构号
			
			if(op.getRoleType().equals(Role.RISK_CONTROL_LEAD.getCode()) || 
			   op.getRoleType().equals(Role.RISK_CONTROL_OPERATORS.getCode())  ){
				handleResultListForCollarPieces(op);
			}
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
			return SUCCESS;
	}
	
	@Action(value="saveCollarPieces")
	public String saveCollarPieces(){
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		PrintWriter pw = null;
		JSONObject json = new JSONObject();
		try {
			
			
			getResponse().setCharacterEncoding("utf-8");
			pw = getResponse().getWriter();
			
			logger.info(op.getRealName()+"开始领取商户,商户号是："+merInfoIdList);
			List<String> rsList = merinfoService.updateTReceiveInfo(op,merInfoIdList);
			
			json.put("rsList", rsList);
			pw.write(json.toString());
						
		} catch (Exception e) {
			logger.error("领件异常");
			logger.error(e.getMessage(),e);
//			json.put("msg", "领取异常");
//			json.put("boo", false);
//			pw.write(json.toString());
		}finally{
			if(pw != null){
				pw.close();
			}
		}
		
		return null;
	}
	 
	/**
	 * 查询下级id
	 * */
	private void querySon(Operators op){
		try {
			/*if(op.getRoleType().equals(Role.AGENT.getCode())  ){ //代理商
				 List<Operators> operatosList = merinfoService.listAllSubMerchants(op.getId());
				 String obj="'";
				 for (int i = 0; i < operatosList.size(); i++) {
						obj += String.valueOf(operatosList.get(i).getId());
						if(i+1 < operatosList.size()){
							obj+="','";
						}else{
							obj+="'";
						}
				  }
			     searchCondition.setObj(obj);
			}else if(op.getRoleType().equals(Role.AGENT_BUSS.getCode())){//业务员
				 searchCondition.setOpId(String.valueOf(op.getId()));
			}*/
			searchCondition.setRoleId(op.getRoleType());// 角色
			searchCondition.setOpId(String.valueOf(op.getId()));//当前人员id
		} catch (Exception e) {
			logger.error("====加载下级关系出错====",e);
		}
	}
	
	/**
	 * 处理查询结果
	 * @throws Exception 
	 * @throws ServiceException 
	 * */
	private void handleResultList(Operators  op) throws Exception {
		try {
			int rows = pageService.countSQL(searchCondition);
			List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
			if (rows > 0) {
				searchRsList = pageService.findAllSQL(searchCondition, 
													calcuStart(getCurrentPage()),
													Constance.PAGE_MAX_SIZE);
				if (searchRsList.size() > 0 && searchRsList != null) {
					 if((searchCondition.getRoleId().equals(Role.SYSTEM.getCode())||
						searchCondition.getRoleId().equals(Role.RISK_CONTROL_LEAD.getCode())||
						searchCondition.getRoleId().equals(Role.RISK_CONTROL_OPERATORS.getCode())) && searchCondition.getMerinfoFlag()==3){//管理员、机构管理员、风控角色
						 msList=handleDetailFor05(searchRsList,op);
					 }else{
						 msList=handleDetail(searchRsList,op);
					 }
				}
			}
			if("48502000".equals(searchCondition.getOneOrgCode()) || "".equals(searchCondition.getOneOrgCode()) || searchCondition.getOneOrgCode() == null){
				searchCondition.setOperationFlag("1");	//系统管理员所属
			}else{
				searchCondition.setOperationFlag("2");	//机构所属
			}
			this.setTotalPage(this.calcuTotalPage(rows));
			getRequest().setAttribute("COUNT", rows);//统计次数
			getRequest().setAttribute(SEARCH_RS_LIST, msList);
			getRequest().setAttribute(CURRENT_PAGE, this.getCurrentPage());
			getRequest().setAttribute(TOTAOL_PAGE, this.getTotalPage());
			getRequest().setAttribute("opid", op.getId());
			if("10".equals(op.getRoleType())||"11".equals(op.getRoleType())){
			getRequest().setAttribute("flag1",op.getSuperiorId());
			}else{
				getRequest().setAttribute("flag1","aa");
			}
			
			getRequest().setAttribute("operationFlag", searchCondition.getOperationFlag());
			setSearchToConditionSession(searchCondition);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			throw new Exception("查询失败",e);
		}
	 
	}
	
	//审核查询
	private List<MerinfoSearchBean> handleDetailFor05(List<Object> objList,Operators  op) throws Exception{
		List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
		try {
			Iterator iterator = objList.iterator();
			while (iterator.hasNext()) {
				Object[] obj = (Object[]) iterator.next();
				MerinfoSearchBean msb = new MerinfoSearchBean();
				msb.setMid(Constance.Null2EmptyTrim(obj[0]));  //商户号
				msb.setMerName(Constance.Null2EmptyTrim(obj[1])); //商户简称
				msb.setMerBrName(Constance.Null2EmptyTrim(obj[2]));//商户注册名称
				msb.setMerKind(Constance.Null2EmptyTrim(obj[3]));//机构名称
				msb.setPerName(Constance.Null2EmptyTrim(obj[4])); //商户联系人
				String phone=Constance.Null2EmptyTrim(obj[5]);//联系人手机号
				if(null!=op.getAgentType() && !op.getAgentType().equals("1") && null!=phone && phone.length()>4){
					msb.setPerPhone(phone.substring(0, 3)+"****"+phone.substring(phone.length()-4));//手机号
				}else{
					msb.setPerPhone(phone);//手机号
				}
				msb.setInterContact(Constance.Null2EmptyTrim(obj[6])); //法人
				String cardNo=Constance.Null2EmptyTrim(obj[7]);//法人证件号
				if(null!=op.getAgentType() && !op.getAgentType().equals("1")  && null!=cardNo && cardNo.length()>4){
					msb.setCardNo(cardNo.substring(0,3)+"****"+cardNo.substring(cardNo.length()-4));//证件号
				}else{
					msb.setCardNo(cardNo);//证件号
				}
				msb.setFlagCode(Constance.Null2EmptyTrim(obj[8]));//营业执照
				msb.setAddr(Constance.Null2EmptyTrim(obj[9])); //地址
				msb.setFlag(MerinfoStatus.getName(Constance.Null2EmptyTrim(obj[10])));//状态
				msb.setCompanyName(Constance.Null2EmptyTrim(obj[11])); //所属分公司
				msb.setOneAgentName(Constance.Null2EmptyTrim(obj[12]));//所属一级代理
				msb.setAgentId(Constance.Null2EmptyTrim(obj[13]));//直属代理商
				
				msb.setRsvl(Constance.Null2EmptyTrim(obj[14]));//结算银行账户名称
				String account=Constance.Null2EmptyTrim(obj[15]);
				/*if(account!=null && account.length()>4){
					msb.setRsvl3(account.substring(0, 4)+"****"+account.substring(account.length()-4));//结算银行账户
				}else{*/
					msb.setRsvl3(account);//结算银行账户
				//}
				msb.setAmount1(Constance.Null2EmptyTrim(obj[16]));//结算银行名称
				msb.setAmount2(Constance.Null2EmptyTrim(obj[17]));//联行号
				/*String[] cycleList=merinfoService.queryMchtBizDealArray(msb.getMid(),false,true);//根据商户查询结算周期
				msb.setMerCycle(cycleList);*/
				msb.setEngName(Constance.Null2EmptyTrim(obj[18]));
				msb.setGroupCd(Constance.Null2EmptyTrim(obj[21]));
				String[] productCodeFlag=merinfoService.queryMchtBizDealArray(msb.getMid(), false, false);
				String[] cycleList={"",""};
				if(Constant.STR_NUMBER_ONE.equals(msb.getGroupCd()) && (Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T1) ||
						Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T0))){
					cycleList[0]=Constance.Null2EmptyTrim(obj[26]);
					if(null!=Constance.Null2EmptyTrim(obj[27]) && !Constance.Null2EmptyTrim(obj[27]).equals("")){
						String j="";
						if(null!=cycleList[0] && !cycleList[0].equals("")){
							j="+";
						}
						cycleList[1]=j+Constance.Null2EmptyTrim(obj[27]);
					}
				}else{
					cycleList[0]=Constance.Null2EmptyTrim(obj[19]);
					if(null!=Constance.Null2EmptyTrim(obj[20]) && !Constance.Null2EmptyTrim(obj[20]).equals("")){
						String j="";
						if(null!=cycleList[0] && !cycleList[0].equals("")){
							j="+";
						}
						cycleList[1]=j+Constance.Null2EmptyTrim(obj[20]);
					}
				}
				msb.setMerCycle(cycleList);
				msb.setNationCd(Constance.Null2EmptyTrim(obj[22]));
				msb.setIsGroup(Constance.Null2EmptyTrim(obj[23]));
				msb.setExct1(Constance.Null2EmptyTrim(obj[25]));	//rec_upd_opr
				msb.setRecUpdOpr(Constance.Null2EmptyTrim(obj[28]));
				msList.add(msb);
			}
		} catch (Exception e) {
			throw new Exception("处理结果失败",e);
		}
		return msList;
	}
	//查询状态为领件的处理方法
		private List<MerinfoSearchBean> handleDetail(List<Object> objList,Operators  op) throws Exception{
			List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
			try {
				Iterator iterator = objList.iterator();
				while (iterator.hasNext()) {
					Object[] obj = (Object[]) iterator.next();
					MerinfoSearchBean msb = new MerinfoSearchBean();
					msb.setMid(Constance.Null2EmptyTrim(obj[0]));
					msb.setMerName(Constance.Null2EmptyTrim(obj[1]));
					msb.setMerBrName(Constance.Null2EmptyTrim(obj[2]));
					msb.setMerKind(Constance.Null2EmptyTrim(obj[3]));
					msb.setPerName(Constance.Null2EmptyTrim(obj[4]));
					String phone=Constance.Null2EmptyTrim(obj[5]);
					if(null!=op.getAgentType() && !op.getAgentType().equals("1") && phone!=null && phone.length()>3){
						msb.setPerPhone(phone.substring(0, 3)+"****"+phone.substring(phone.length()-4));//手机号
					}else{
						msb.setPerPhone(phone);//手机号
					}
					msb.setInterContact(Constance.Null2EmptyTrim(obj[6]));
					String cardNo=Constance.Null2EmptyTrim(obj[7]);
					if(null!=op.getAgentType() && !op.getAgentType().equals("1") && null!=cardNo && cardNo.length()>4){
						msb.setCardNo(cardNo.substring(0,3)+"****"+cardNo.substring(cardNo.length()-4));//证件号
					}else{
						msb.setCardNo(cardNo);//证件号
					}
					msb.setFlagCode(Constance.Null2EmptyTrim(obj[8]));
					msb.setAddr(Constance.Null2EmptyTrim(obj[9]));
					msb.setFlag(MerinfoStatus.getName(Constance.Null2EmptyTrim(obj[10])));//状态
					msb.setCompanyName(Constance.Null2EmptyTrim(obj[11])); //所属分公司
					msb.setOneAgentName(Constance.Null2EmptyTrim(obj[12]));//所属一级代理
					msb.setAgentId(Constance.Null2EmptyTrim(obj[13]));//直属代理商
					
					msb.setRsvl(Constance.Null2EmptyTrim(obj[14]));//结算银行账户名称
					String account=Constance.Null2EmptyTrim(obj[15]);
					msb.setGroupCd(Constance.Null2EmptyTrim(obj[20])); //商户类型
					/*if(account!=null && account.length()>4){
						msb.setRsvl3(account.substring(0, 4)+"****"+account.substring(account.length()-4));//结算银行账户
					}else{*/
						msb.setRsvl3(account);//结算银行账户
					//}
					msb.setAmount1(Constance.Null2EmptyTrim(obj[16]));//结算银行名称
					msb.setAmount2(Constance.Null2EmptyTrim(obj[17]));//联行号
					/*String[] cycleList=merinfoService.queryMchtBizDealArray(msb.getMid(),false,true);//根据商户查询结算周期
					msb.setMerCycle(cycleList);*/
					String[] productCodeFlag=merinfoService.queryMchtBizDealArray(msb.getMid(), false, false);
					String[] cycleList={"",""};
					if(Constant.STR_NUMBER_ONE.equals(msb.getGroupCd()) && (Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T1) ||
							Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T0))){
						cycleList[0]=Constance.Null2EmptyTrim(obj[25]);
						if(null!=Constance.Null2EmptyTrim(obj[26]) && !Constance.Null2EmptyTrim(obj[26]).equals("")){
							String j="";
							if(null!=cycleList[0] && !cycleList[0].equals("")){
								j="+";
							}
							cycleList[1]=j+Constance.Null2EmptyTrim(obj[26]);
						}
					}else{
						cycleList[0]=Constance.Null2EmptyTrim(obj[18]);
						if(null!=Constance.Null2EmptyTrim(obj[19]) && !Constance.Null2EmptyTrim(obj[19]).equals("")){
							String j="";
							if(null!=cycleList[0] && !cycleList[0].equals("")){
								j="+";
							}
							cycleList[1]=j+Constance.Null2EmptyTrim(obj[19]);
						}
					}
					msb.setMerCycle(cycleList);
					msb.setNationCd(Constance.Null2EmptyTrim(obj[21]));
					msb.setIsGroup(Constance.Null2EmptyTrim(obj[22]));
					//rec_upd_opr
					msb.setExct1(Constance.Null2EmptyTrim(obj[24]));
					msb.setRecUpdOpr(Constance.Null2EmptyTrim(obj[27]));
					msList.add(msb);
				}
			} catch (Exception e) {
				throw new Exception("处理结果失败",e);
			}
			return msList;
		}
	
	// 初始化页面信息
	private void init(boolean city) throws Exception {
		try {
			Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);//当前操作员
			getRequest().setAttribute("opers", op.getRealName());//申请人名称
			getRequest().setAttribute("groupCd", op.getGroupCd());//申请人的直间连属性
			
			if( city==true &&null!=op.getAreaCode()&& !op.getAreaCode().equals("") &&  !op.getAreaCode().trim().equals("0000")  ){
				if(op.getAreaCode().trim().equals("3600") || op.getAreaCode().trim().equals("8500")){ //安徽和青海的省份代码
					addActionMessage("提示：安徽和青海暂停进件业务，具体详情请联系相关业务人员！");
					return;
				}
				String areaCode=ConfigMerinfoUtil.getGBProviceCodeForInsert(op.getAreaCode(),false);//地区码编码
				String provicesName=ConfigMerinfoUtil.getGBProviceCodeForInsert(op.getAreaCode(),true);//地区码名称
				getRequest().setAttribute("areaCode", areaCode);//地区码编码
				getRequest().setAttribute("proName", provicesName);//地区码名称
			}
			getRequest().setAttribute("certifType", ConfigProperties.getSysDB1("CERTIF_TYPE",true));//证件类型
			getRequest().setAttribute("posType", ConfigProperties.getSysDB1("Terminal_Type",true));//终端类型
			getRequest().setAttribute("org", op.getOrgCode());//机构
			getRequest().setAttribute("bankList", ConfigProperties.getSysDB1("UP_BC_CD",false));//银行信息
			Map<String, String> bMap = ConfigProperties.getSysDB1("UP_BC_CD",false);
			getRequest().setAttribute("bMapToList", bMap.values());//银行信息
			getRequest().setAttribute("mccMapToList", ConfigProperties.getHyMccTypeProperties().values());//mcc
			getRequest().setAttribute("roleType", op.getRoleType()); //登录人角色
			if((Role.OPERATORS_COMM.getCode().equals(op.getRoleType()) || Role.OPERATORS_LEAD.getCode().equals(op.getRoleType()))&&"2".equals(op.getGroupCd())){
					List<TblInsInf> orgList = orgService.queryAllOrgList();
					List<Operators> orgMainList = powerInfoService.queryOperatorsByParams(op.getRoleType(), op.getOneagentid());
					getRequest().setAttribute("orgList", orgList);
					getRequest().setAttribute("orgMainList", orgMainList);
			}
			Map developPersonMap= new HashMap();
			if(("10".equals(op.getRoleType())||"18".equals(op.getRoleType()) )&&"2".equals(op.getGroupCd())){
				developPersonMap=merinfoService.getOpIdsTreeBySuperId(op);
			}
			getRequest().setAttribute("developPersonMap", developPersonMap);//发展人列表
		} catch (Exception e) {
			logger.error("商户查询初始化失败", e);
			throw new Exception("商户查询初始化失败");
		}
	}
	/**
	 * 风控查看驳回信息初始化
	 * @author whuan
	 * */
	private void initComplete(TblEditMchtInf  tmpMer) throws Exception {
			try {
				Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);//当前操作员
				 //判断连接方式（直连、间联、间联直营）
				getRequest().setAttribute("groupCd", tmpMer.getGroupCD());
				//获取地区编码
				getRequest().setAttribute("areaCode", tmpMer.getProvCd());//地区码编码(省份)
				String a= ConfigMerinfoUtil.getGBProviceName(tmpMer.getProvCd());
				getRequest().setAttribute("proName", ConfigMerinfoUtil.getGBProviceName(tmpMer.getProvCd()));//地区码名称
				 
				getRequest().setAttribute("certifType", ConfigProperties.getSysDB1("CERTIF_TYPE",true));//证件类型
				getRequest().setAttribute("posType", ConfigProperties.getSysDB1("Terminal_Type",true));//终端类型
				getRequest().setAttribute("org", tmpMer.getBankBelongCd());//机构(暂时无用)
				getRequest().setAttribute("bankList", ConfigProperties.getSysDB1("UP_BC_CD",false));//银行信息
				Map<String, String> bMap = ConfigProperties.getSysDB1("UP_BC_CD",false);
				getRequest().setAttribute("bMapToList", bMap.values());//银行信息
				getRequest().setAttribute("mccMapToList", ConfigProperties.getHyMccTypeProperties().values());//mcc
				Map developPersonMap= new HashMap();
				String roleType = "";
				if(tmpMer.getMchtExtendInfo() != null){
					developPersonMap=merinfoService.getOpIdsTreeBySuperId(op);
					roleType = Role.OPERATORS_LEAD.getCode();
				}
				getRequest().setAttribute("roleType", roleType); //登录人角色
				getRequest().setAttribute("developPersonMap", developPersonMap);//发展人列表
				List<TblInsInf> orgList = orgService.queryAllOrgList();
				List<orgMainBean> orgMainList = orgService.listOrgMainByOrgCode(tmpMer.getBankBelongCd());
				getRequest().setAttribute("orgList", orgList);
				getRequest().setAttribute("orgMainList", orgMainList);
			} catch (Exception e) {
				logger.error("商户查询初始化失败", e);
				throw new Exception("商户查询初始化失败");
			}
		}
	/**
	 * 下载图片压缩包
	 */

	@Action(value="zipExport",results = {@Result(name="success",type="stream"
			,params = { "contentType", "application/octet-stream", "inputName",  
			            "zipFile","contentDisposition",  "attachment;filename=${zipName}.zip",
			            "bufferSize", "1024*3" }),@Result(name="error",location="/pages/merinfo/checkMerinfoTwo.jsp") }) 
	public String exportImageZip()
	{
		Operators op = (Operators) ActionContext.getContext().getSession().get(Constant.SESSION_LOGIN_MERCHANT);
		
		Map<String,String> urlmap = new HashMap<String,String>();
		List list = merinfoImageService.queryMerinfoImage(merinfo.getId());
		for (Object obj : list) {
			TblEditMchtPicture pic = (TblEditMchtPicture) obj;
			urlmap.put(pic.getFileName(), pic.getUrl());
		}

		String zipFilePath =Utils.getConfigValue("ZIP_FILE_PATH");//压缩包存放的文件夹
		boolean falg = HttpFileToZipUtil.httpFileToZip(zipFilePath, getZipName(),urlmap);
		if(falg)
		{
			File file = new File(zipFilePath,getZipName()+".zip");
			try {
				zipFile = new FileInputStream(file);
				HttpFileToZipUtil.deletefile(zipFilePath);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return ERROR;
			}
			
			return SUCCESS;
		}
		else 
			return ERROR;
	}
	
	/**
	 * 商户批量操作页面初始化
	 */
	@Action(value="batchMerFileImportInit",results={@Result(name="success",location="/pages/merinfo/batchMerFileImport.jsp")})
	public String batchFreezeInit(){
		Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		if(op.getRoleType().equals(Role.AGENT.getCode())&&!"sdsyb".equals(op.getAccountNo())) {
			addActionError("当前登录账号无权限访问!!!");
			return ERROR;
		}
		
		return SUCCESS;
		}
	
	/**
	 * 批量处理商户状态（冻结，解冻，注销）
	 */
	@Action(value="fileImpUpdate",results={@Result(name=SUCCESS,location="/pages/merinfo/batchMerFileImport.jsp"),
			@Result(name = ERROR, location = "/error.jsp")})
	public String fileImpUpdate(){
		Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		if(op.getRoleType().equals(Role.AGENT.getCode())&&!"sdsyb".equals(op.getAccountNo())) {
			addActionError("当前登录账号无权限访问!!!");
			return ERROR;
		}
		String context = "";
		String returnStr = "";
		if("0".equals(dealType)){
			context = "冻结";
			returnStr = SUCCESS;
		}else if("1".equals(dealType)){
			context = "解冻";
			returnStr = SUCCESS;
		}else if("2".equals(dealType)){
			context = "注销";
			returnStr = SUCCESS;
		}else if("3".equals(dealType)){
			context = "开通";
			returnStr = SUCCESS;
		}
		logger.info(op.getAccountNo()+"开始进行批量"+context+"操作");
		ExcelUtil excelUtil = new ExcelUtil();
		try{
			FileInputStream fileInputStream= new FileInputStream(excelFile);//struts2自动以流的形式完成文件上传
			List<List<String>> arrList = excelUtil.readExcel(fileInputStream);//调用excel模块的方法读取文件  返回要导入的数据
			if(arrList.size()>1){
				List<String> list= merinfoService.changeMerinfoStatusBanch(arrList, dealType, op.getAccountNo());
				if(list.get(0).equals("000")){
					logger.info(op.getAccountNo()+"批量"+context+"操作成功");
					getRequest().setAttribute("msg", context+"成功");
				}else{
					logger.info(op.getAccountNo()+"批量"+context+"操作失败"+list.get(1).toString());
					getRequest().setAttribute("msg", context+"失败"+"，请联系管理员");
				}
			}else{
				logger.info(op.getAccountNo()+"批量"+context+"操作失败"+"，数据不能为空");
				getRequest().setAttribute("msg", "数据不能为空");
			}
			
		}catch(Exception e){
			logger.error(op.getAccountNo()+"批量"+context+"操作失败"+e.getMessage());
			getRequest().setAttribute("msg", context+"失败"+"，请核对后重新操作");
			return ERROR;
		}
		return returnStr;
	}
	
	
	/**
	 * 处理查询结果
	 * @throws Exception 
	 * @throws ServiceException 
	 * */
	private void handleResultListForCollarPieces(Operators  op) throws Exception {
		try {
			int rows = pageService.countSQL(searchCondition);
			List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
			if (rows > 0) {
				searchRsList = pageService.findAllSQL(searchCondition, 
													calcuStart(getCurrentPage()),
													Constance.PAGE_MAX_SIZE);
				if (searchRsList.size() > 0 && searchRsList != null) {
					 if((searchCondition.getRoleId().equals(Role.SYSTEM.getCode())||
						searchCondition.getRoleId().equals(Role.RISK_CONTROL_LEAD.getCode())||
						searchCondition.getRoleId().equals(Role.RISK_CONTROL_OPERATORS.getCode())) && searchCondition.getMerinfoFlag()==3){//管理员、风控角色
						 msList=handleDetailForCollar(searchRsList,op);
					 }else{
						 msList=handleDetailForCollar1(searchRsList,op);
					 }
				}
			}
			this.setTotalPage(this.calcuTotalPage(rows));
			getRequest().setAttribute("COUNT", rows);//统计次数
			getRequest().setAttribute(SEARCH_RS_LIST, msList);
			getRequest().setAttribute(CURRENT_PAGE, this.getCurrentPage());
			getRequest().setAttribute(TOTAOL_PAGE, this.getTotalPage());
			setSearchToConditionSession(searchCondition);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
			throw new Exception("查询失败",e);
		}
	 
	}
	
	private List<MerinfoSearchBean> handleDetailForCollar(List<Object> objList,Operators  op) throws Exception{
		List<String> mccList = Arrays.asList("5411","4900","5541","5542","4111","4121","4131","4511","4784","8062","8011",
				"8021","8031","8041","8042","8049","8099","8211","8220","8351","8241","8398");
		List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
		try {
			Iterator iterator = objList.iterator();
			while (iterator.hasNext()) {
				Object[] obj = (Object[]) iterator.next();
				MerinfoSearchBean msb = new MerinfoSearchBean();
				msb.setMid(Constance.Null2EmptyTrim(obj[0]));  //商户号
				msb.setMerName(Constance.Null2EmptyTrim(obj[1])); //商户简称
				msb.setMerBrName(Constance.Null2EmptyTrim(obj[2]));//商户注册名称
				msb.setMerKind(Constance.Null2EmptyTrim(obj[3]));//机构名称
				msb.setPerName(Constance.Null2EmptyTrim(obj[4])); //商户联系人
				String phone=Constance.Null2EmptyTrim(obj[5]);//联系人手机号
				if(null!=op.getAgentType() && !op.getAgentType().equals("1") && null!=phone && phone.length()>4){
					msb.setPerPhone(phone.substring(0, 3)+"****"+phone.substring(phone.length()-4));//手机号
				}else{
					msb.setPerPhone(phone);//手机号
				}
				msb.setInterContact(Constance.Null2EmptyTrim(obj[6])); //法人
				String cardNo=Constance.Null2EmptyTrim(obj[7]);//法人证件号
				if(null!=op.getAgentType() && !op.getAgentType().equals("1")  && null!=cardNo && cardNo.length()>4){
					msb.setCardNo(cardNo.substring(0,3)+"****"+cardNo.substring(cardNo.length()-4));//证件号
				}else{
					msb.setCardNo(cardNo);//证件号
				}
				msb.setFlagCode(Constance.Null2EmptyTrim(obj[8]));//营业执照
				msb.setAddr(Constance.Null2EmptyTrim(obj[9])); //地址
				msb.setFlag(MerinfoStatus.getName(Constance.Null2EmptyTrim(obj[10])));//状态
				msb.setCompanyName(Constance.Null2EmptyTrim(obj[11])); //所属分公司
				msb.setOneAgentName(Constance.Null2EmptyTrim(obj[12]));//所属一级代理
				msb.setAgentId(Constance.Null2EmptyTrim(obj[13]));//直属代理商
				
				msb.setRsvl(Constance.Null2EmptyTrim(obj[14]));//结算银行账户名称
				String account=Constance.Null2EmptyTrim(obj[15]);
				/*if(account!=null && account.length()>4){
					msb.setRsvl3(account.substring(0, 4)+"****"+account.substring(account.length()-4));//结算银行账户
				}else{*/
					msb.setRsvl3(account);//结算银行账户
				//}
				msb.setAmount1(Constance.Null2EmptyTrim(obj[16]));//结算银行名称
				msb.setAmount2(Constance.Null2EmptyTrim(obj[17]));//联行号
				msb.setGroupCd(Constance.Null2EmptyTrim(obj[21]));
				/*String[] cycleList=merinfoService.queryMchtBizDealArray(msb.getMid(),false,true);//根据商户查询结算周期
				msb.setMerCycle(cycleList);*/
				msb.setEngName(Constance.Null2EmptyTrim(obj[18]));
				String[] productCodeFlag=merinfoService.queryMchtBizDealArray(msb.getMid(), false, false);
				String[] cycleList={"",""};
				if(Constant.STR_NUMBER_ONE.equals(msb.getGroupCd()) && (Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T1) ||
						Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T0))){
					cycleList[0]=Constance.Null2EmptyTrim(obj[26]);
					if(null!=Constance.Null2EmptyTrim(obj[27]) && !Constance.Null2EmptyTrim(obj[27]).equals("")){
						String j="";
						if(null!=cycleList[0] && !cycleList[0].equals("")){
							j="+";
						}
						cycleList[1]=j+Constance.Null2EmptyTrim(obj[27]);
					}
				}else{
					cycleList[0]=Constance.Null2EmptyTrim(obj[19]);
					if(null!=Constance.Null2EmptyTrim(obj[20]) && !Constance.Null2EmptyTrim(obj[20]).equals("")){
						String j="";
						if(null!=cycleList[0] && !cycleList[0].equals("")){
							j="+";
						}
						cycleList[1]=j+Constance.Null2EmptyTrim(obj[20]);
					}
				}
				msb.setMerCycle(cycleList);
				msb.setNationCd(Constance.Null2EmptyTrim(obj[22]));
				msb.setIsGroup(Constance.Null2EmptyTrim(obj[23]));
				msb.setMcc(Constance.Null2EmptyTrim(obj[24]));
				/*if(mccList.contains(msb.getMcc())){
					msList.add(msb);
				}*/
				msList.add(msb);
				
			}
		} catch (Exception e) {
			throw new Exception("处理结果失败",e);
		}
		return msList;
	}

	private List<MerinfoSearchBean> handleDetailForCollar1(List<Object> objList,Operators  op) throws Exception{
		List<String> mccList = Arrays.asList("5411","4900","5541","5542","4111","4121","4131","4511","4784","8062","8011",
				"8021","8031","8041","8042","8049","8099","8211","8220","8351","8241","8398");
		List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
		try {
			Iterator iterator = objList.iterator();
			while (iterator.hasNext()) {
				Object[] obj = (Object[]) iterator.next();
				MerinfoSearchBean msb = new MerinfoSearchBean();
				msb.setMid(Constance.Null2EmptyTrim(obj[0]));
				msb.setMerName(Constance.Null2EmptyTrim(obj[1]));
				msb.setMerBrName(Constance.Null2EmptyTrim(obj[2]));
				msb.setMerKind(Constance.Null2EmptyTrim(obj[3]));
				msb.setPerName(Constance.Null2EmptyTrim(obj[4]));
				String phone=Constance.Null2EmptyTrim(obj[5]);
				if(null!=op.getAgentType() && !op.getAgentType().equals("1") && phone!=null && phone.length()>3){
					msb.setPerPhone(phone.substring(0, 3)+"****"+phone.substring(phone.length()-4));//手机号
				}else{
					msb.setPerPhone(phone);//手机号
				}
				msb.setInterContact(Constance.Null2EmptyTrim(obj[6]));
				String cardNo=Constance.Null2EmptyTrim(obj[7]);
				if(null!=op.getAgentType() && !op.getAgentType().equals("1") && null!=cardNo && cardNo.length()>4){
					msb.setCardNo(cardNo.substring(0,3)+"****"+cardNo.substring(cardNo.length()-4));//证件号
				}else{
					msb.setCardNo(cardNo);//证件号
				}
				msb.setFlagCode(Constance.Null2EmptyTrim(obj[8]));
				msb.setAddr(Constance.Null2EmptyTrim(obj[9]));
				msb.setFlag(MerinfoStatus.getName(Constance.Null2EmptyTrim(obj[10])));//状态
				msb.setCompanyName(Constance.Null2EmptyTrim(obj[11])); //所属分公司
				msb.setOneAgentName(Constance.Null2EmptyTrim(obj[12]));//所属一级代理
				msb.setAgentId(Constance.Null2EmptyTrim(obj[13]));//直属代理商
				
				msb.setRsvl(Constance.Null2EmptyTrim(obj[14]));//结算银行账户名称
				String account=Constance.Null2EmptyTrim(obj[15]);
				/*if(account!=null && account.length()>4){
					msb.setRsvl3(account.substring(0, 4)+"****"+account.substring(account.length()-4));//结算银行账户
				}else{*/
					msb.setRsvl3(account);//结算银行账户
				//}
				msb.setAmount1(Constance.Null2EmptyTrim(obj[16]));//结算银行名称
				msb.setAmount2(Constance.Null2EmptyTrim(obj[17]));//联行号
				msb.setGroupCd(Constance.Null2EmptyTrim(obj[20]));
				/*String[] cycleList=merinfoService.queryMchtBizDealArray(msb.getMid(),false,true);//根据商户查询结算周期
				msb.setMerCycle(cycleList);*/
				String[] productCodeFlag=merinfoService.queryMchtBizDealArray(msb.getMid(), false, false);
				String[] cycleList={"",""};
				if(Constant.STR_NUMBER_ONE.equals(msb.getGroupCd()) && (Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T1) ||
						Arrays.asList(productCodeFlag).contains(ConfigMerinfoUtil.DIRECT_FUNCTION_T0))){
					cycleList[0]=Constance.Null2EmptyTrim(obj[25]);
					if(null!=Constance.Null2EmptyTrim(obj[26]) && !Constance.Null2EmptyTrim(obj[26]).equals("")){
						String j="";
						if(null!=cycleList[0] && !cycleList[0].equals("")){
							j="+";
						}
						cycleList[1]=j+Constance.Null2EmptyTrim(obj[26]);
					}
				}else{
					cycleList[0]=Constance.Null2EmptyTrim(obj[18]);
					if(null!=Constance.Null2EmptyTrim(obj[19]) && !Constance.Null2EmptyTrim(obj[19]).equals("")){
						String j="";
						if(null!=cycleList[0] && !cycleList[0].equals("")){
							j="+";
						}
						cycleList[1]=j+Constance.Null2EmptyTrim(obj[19]);
					}
				}
				msb.setMerCycle(cycleList);
				msb.setGroupCd(Constance.Null2EmptyTrim(obj[20])); 
				msb.setNationCd(Constance.Null2EmptyTrim(obj[21]));
				msb.setIsGroup(Constance.Null2EmptyTrim(obj[22]));
				msb.setMcc(Constance.Null2EmptyTrim(obj[23]));
				/*if(mccList.contains(msb.getMcc())){
					msList.add(msb);
				}*/
				msList.add(msb);
			}
		} catch (Exception e) {
			throw new Exception("处理结果失败",e);
		}
		return msList;
	}
	
	
	// 直营商户(预审核)查询初始化
	@Action(value = "preDirectMerReview", results = {	
			@Result(name =SUCCESS, location = "/pages/merinfo/preDirectMerReviewList.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String preDirectMerReview() {
		try {
			Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
			Operators op1=null;
			Long superId1;
			String superRole=null;
			//查询运营人员上级
			if(op.getRoleType().equals(Role.OPERATORS_COMM.getCode())){
				op1=iPowerInfoService.queryOperByOneOrgCode(String.valueOf(op.getSuperiorId()));
				superRole=op1.getRoleType();
				superId1=op1.getSuperiorId();
			}else{
				superId1=op.getSuperiorId();
			}
			//收单事业部开的直营分公司账号或分公司运营
			//直营分公司账号或分公司运营
			if(!(((op.getRoleType().equals(Role.OPERATORS_COMM.getCode())&&op1.getSuperiorId()!=11191045&&superRole.equals("02"))
				||(op.getRoleType().equals(Role.O_MANAGER.getCode())&&op.getId()!=11191045)
				||op.getRoleType().equals(Role.OPERATORS_LEAD.getCode()))&&op.getGroupCd().equals("2"))){
			 addActionError("无权限访问");
				 return ERROR;
			 }
			 return SUCCESS;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
			addActionError(e.getMessage());
			return ERROR;
		}

	}
	
	// 直营商户(待审核)查询
	@Action(value = "queryPreDirectMerReviewList", results = {
			@Result(name = SUCCESS, location = "/pages/merinfo/preDirectMerReviewList.jsp"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String queryPreDirectMerReviewList() {
		Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		try {
			Operators op1=null;
			Long superId1;
			String superRole=null;
			//查询运营人员上级
			if(op.getRoleType().equals(Role.OPERATORS_COMM.getCode())){
				op1=iPowerInfoService.queryOperByOneOrgCode(String.valueOf(op.getSuperiorId()));
				superRole=op1.getRoleType();
				superId1=op1.getSuperiorId();
			}else{
				superId1=op.getSuperiorId();
			}
			//收单事业部开的直营分公司账号或分公司运营
			//直营分公司账号或分公司运营
			if(!(((op.getRoleType().equals(Role.OPERATORS_COMM.getCode())&&op1.getSuperiorId()!=11191045&&superRole.equals("02"))
				||(op.getRoleType().equals(Role.O_MANAGER.getCode())&&op.getId()!=11191045)
				||op.getRoleType().equals(Role.OPERATORS_LEAD.getCode()))&&op.getGroupCd().equals("2"))){
			 addActionError("无权限访问");
				 return ERROR;
			 }
			if (searchCondition == null) {
				searchCondition = (MerinfoSearchCondtion) getSearchConditionFromSession();
				if (searchCondition == null) {
					searchCondition = new MerinfoSearchCondtion();
				}
			}
		    searchCondition.setOrgCode(op.getOrgCode());//当前查询人员所属机构
			searchCondition.setStatus(MerinfoStatus.S_14.getCode());//审核查询
			searchCondition.setRkopId(String.valueOf(op.getId()));//操作员id
			searchCondition.setRoleId(op.getRoleType());//角色
			//必要字段
			searchCondition.setPreDirectMerReviewFlag("1");//直营商户审核标识
			searchCondition.setJgFlag(String.valueOf(op.getId()));//当前人分公司id
			searchCondition.setOneAgentId(op.getOneagentid());//当前人分公司id
			searchCondition.setCompanyid(op.getCompanyid());//当前人分公司id
			searchCondition.setMerinfoFlag(4);//查询状态标识'14'直营进件中
			int rows = pageService.countSQL(searchCondition);
			List<MerinfoSearchBean> msList = new ArrayList<MerinfoSearchBean>();
			if (rows > 0) {
				 searchRsList = pageService.findAllSQL(searchCondition, 
														calcuStart(getCurrentPage()),
														Constance.PAGE_MAX_SIZE);
				 if (searchRsList.size() > 0 && searchRsList != null) {
					 msList=handleDetail(searchRsList,op);
				 }
				this.setTotalPage(this.calcuTotalPage(rows));
				getRequest().setAttribute("COUNT", rows);//统计次数
				getRequest().setAttribute(SEARCH_RS_LIST, msList);
				getRequest().setAttribute(CURRENT_PAGE, this.getCurrentPage());
				getRequest().setAttribute(TOTAOL_PAGE, this.getTotalPage());
				getRequest().setAttribute("opid", op.getId());
				getRequest().setAttribute("operationFlag", searchCondition.getOperationFlag());
				setSearchToConditionSession(searchCondition);
		    }
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
			return SUCCESS;
	}
	
	
	// 审核页面
	@Action(value = "preCheckMerchantJsp", results = { 
			@Result(name = SUCCESS, location = "/pages/merinfo/preCheckMerinfo.jsp"),
		    @Result(name =INPUT, type = "chain", location = "queryPreDirectMerReviewList"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String preCheckMerchantJsp() {
		Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		try {
			Operators op1=null;
			Long superId1;
			String superRole=null;
			//查询运营人员上级
			if(op.getRoleType().equals(Role.OPERATORS_COMM.getCode())){
				op1=iPowerInfoService.queryOperByOneOrgCode(String.valueOf(op.getSuperiorId()));
				superRole=op1.getRoleType();
				superId1=op1.getSuperiorId();
			}else{
				superId1=op.getSuperiorId();
			}
			//收单事业部开的直营分公司账号或分公司运营
			//直营分公司账号或分公司运营
			if(!(((op.getRoleType().equals(Role.OPERATORS_COMM.getCode())&&op1.getSuperiorId()!=11191045&&superRole.equals("02"))
				||(op.getRoleType().equals(Role.O_MANAGER.getCode())&&op.getId()!=11191045)
				||op.getRoleType().equals(Role.OPERATORS_LEAD.getCode()))&&op.getGroupCd().equals("2"))){
			 addActionError("无权限访问");
				 return ERROR;
			 }
			if (null==merinfo || merinfo.getId() == null || merinfo.getId().equals("")) {
				addActionError("异常，审核商户信息失败");
				return ERROR;
			}
			
			//商户信息回显
			merinfo=merinfoService.queryPreMerinfoTmpInfo(merinfo.getId(),true,true);
			String[] productCodeFlag=merinfoService.queryMchtBizDealArray(merinfo.getId(), false, false);
			getRequest().setAttribute("mcc", ConfigProperties.getHyMccTypeProperties());//mccauditingMap
			logger.info("------"+ConfigProperties.getUnionProviceProperties().size()+"------");
			getRequest().setAttribute("provinesMap", ConfigProperties.getUnionProviceProperties());//32域省份
			getRequest().setAttribute("auditingMap",ConfigMerinfoUtil.getAuditingMap());//审核
			getRequest().setAttribute("rejectTypeList",Arrays.asList(RejectType.values()));
			if("1".equals(merinfo.getMchtExtendInfo().getBackup2())){
				getRequest().setAttribute("bhxx","1");//页面是否增加驳回信息
			}
			//查询32域信息
			String code32=userService.queryAreaDetailBy32Code(merinfo.getUcBccd());
			getRequest().setAttribute("code32",code32);
            //所属代理商
			String orgName = "";
			String ext1 = merinfo.getExt1();
			if(ext1 != null && ext1.length() > 0){
				Operators opr = powerInfoService.loadOperatorsById(Long.valueOf(ext1));
				orgName = opr.getRealName();
			}
			getRequest().setAttribute("orgName", orgName);
			getRequest().setAttribute("posFunction", ConfigMerinfoUtil.getPosFunction(ConfigMerinfoUtil.ALL_FUNCTION, true));//开通产品信息
			getRequest().setAttribute("roleType", op.getRoleType());
			getRequest().setAttribute("groupCd", merinfo.getGroupCD());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * 直营商户审核操作
	 * */
	@Action(value = "preCheckNewMerinfo", 
			results = { @Result(name =SUCCESS, type = "chain", location = "queryPreDirectMerReviewList"),
			@Result(name = ERROR, location = "/error.jsp") })
	public String preCheckNewMerinfo() {
		try {
			Operators op = (Operators) getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
			Long superId1;
			Operators op1=null;
			String superRole=null;
			//查询运营人员上级
			if(op.getRoleType().equals(Role.OPERATORS_COMM.getCode())){
				op1=iPowerInfoService.queryOperByOneOrgCode(String.valueOf(op.getSuperiorId()));
				superRole=op1.getRoleType();
				superId1=op1.getSuperiorId();
			}else{
				superId1=op.getSuperiorId();
			}
			//收单事业部开的直营分公司账号或分公司运营
			//直营分公司账号或分公司运营
			if(!(((op.getRoleType().equals(Role.OPERATORS_COMM.getCode())&&op1.getSuperiorId()!=11191045&&superRole.equals("02"))
				||(op.getRoleType().equals(Role.O_MANAGER.getCode())&&op.getId()!=11191045)
				||op.getRoleType().equals(Role.OPERATORS_LEAD.getCode()))&&op.getGroupCd().equals("2"))){
			 addActionError("无权限访问");
				 return ERROR;
			 }
			if (merinfo == null || "".equals(Constance.Null2EmptyTrim(merinfo.getId()))) {
				addActionError("商户号为空，审核出错啦！");
				return ERROR;
			}
			String isCheck=merinfoService.preCheckMerinfo( op,merinfo);
			String[] splitResult=isCheck.split("_");
			addActionMessage(splitResult[0]);
			
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			addActionError(e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
	

	@Override
	protected String getInitPageSize() {
		// TODO Auto-generated method stub
		return Constance.PAGE_MAX_SIZE + "";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.roc.page.PaginationBaseAction#getSearchConditionFromSession()
	 */
	@Override
	protected BaseSearchCondition getSearchConditionFromSession() {
		// TODO Auto-generated method stub
		return (MerinfoSearchCondtion) getSession().getAttribute(SEARCH_SESSION_MERINFO_INFO);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.roc.page.PaginationBaseAction#getSearchConditionFromSubClass()
	 */
	@Override
	protected BaseSearchCondition getSearchConditionFromSubClass() throws Exception {
		// TODO Auto-generated method stub
		return searchCondition;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.roc.page.PaginationBaseAction#setSearchConditionToSubClass(com.roc.
	 * page.BaseSearchCondition)
	 */
	@Override
	protected void setSearchConditionToSubClass(BaseSearchCondition searchCondition) throws Exception {
		this.setSearchConditionToSubClass(searchCondition);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.roc.page.PaginationBaseAction#setSearchToConditionSession(com.roc.
	 * page.BaseSearchCondition)
	 */
	@Override
	protected void setSearchToConditionSession(BaseSearchCondition searchCondition) {
		getSession().setAttribute(SEARCH_SESSION_MERINFO_INFO, searchCondition);
	}

	/*public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	public File getFile1() {
		return file1;
	}

	public void setFile1(File file1) {
		this.file1 = file1;
	}

	public String getFile1ContentType() {
		return file1ContentType;
	}

	public void setFile1ContentType(String file1ContentType) {
		this.file1ContentType = file1ContentType;
	}

	public File getFile2() {
		return file2;
	}

	public void setFile2(File file2) {
		this.file2 = file2;
	}

	public String getFile2ContentType() {
		return file2ContentType;
	}

	public void setFile2ContentType(String file2ContentType) {
		this.file2ContentType = file2ContentType;
	}

	public File getFile3() {
		return file3;
	}

	public void setFile3(File file3) {
		this.file3 = file3;
	}

	public String getFile3ContentType() {
		return file3ContentType;
	}

	public void setFile3ContentType(String file3ContentType) {
		this.file3ContentType = file3ContentType;
	}

	public File getFile4() {
		return file4;
	}

	public void setFile4(File file4) {
		this.file4 = file4;
	}

	public String getFile4ContentType() {
		return file4ContentType;
	}

	public void setFile4ContentType(String file4ContentType) {
		this.file4ContentType = file4ContentType;
	}

	public File getFile5() {
		return file5;
	}

	public void setFile5(File file5) {
		this.file5 = file5;
	}

	public String getFile5ContentType() {
		return file5ContentType;
	}

	public void setFile5ContentType(String file5ContentType) {
		this.file5ContentType = file5ContentType;
	}

	public File getFile6() {
		return file6;
	}

	public void setFile6(File file6) {
		this.file6 = file6;
	}

	public String getFile6ContentType() {
		return file6ContentType;
	}

	public void setFile6ContentType(String file6ContentType) {
		this.file6ContentType = file6ContentType;
	}

	public File getFile7() {
		return file7;
	}

	public void setFile7(File file7) {
		this.file7 = file7;
	}

	public String getFile7ContentType() {
		return file7ContentType;
	}

	public void setFile7ContentType(String file7ContentType) {
		this.file7ContentType = file7ContentType;
	}*/

	public EsmidinfoMerinfo getMerDetail() {
		return merDetail;
	}

	public void setMerDetail(EsmidinfoMerinfo merDetail) {
		this.merDetail = merDetail;
	}

	public TblEditMchtInf getMerinfo() {
		return merinfo;
	}

	public void setMerinfo(TblEditMchtInf merinfo) {
		this.merinfo = merinfo;
	}

	/*public File getFile8() {
		return file8;
	}

	public void setFile8(File file8) {
		this.file8 = file8;
	}

	public String getFile8ContentType() {
		return file8ContentType;
	}

	public void setFile8ContentType(String file8ContentType) {
		this.file8ContentType = file8ContentType;
	}

	public File getFile9() {
		return file9;
	}

	public void setFile9(File file9) {
		this.file9 = file9;
	}

	public String getFile9ContentType() {
		return file9ContentType;
	}

	public void setFile9ContentType(String file9ContentType) {
		this.file9ContentType = file9ContentType;
	}

	public File getFile10() {
		return file10;
	}

	public void setFile10(File file10) {
		this.file10 = file10;
	}

	public String getFile10ContentType() {
		return file10ContentType;
	}

	public void setFile10ContentType(String file10ContentType) {
		this.file10ContentType = file10ContentType;
	}

	public File getFile11() {
		return file11;
	}

	public void setFile11(File file11) {
		this.file11 = file11;
	}

	public String getFile11ContentType() {
		return file11ContentType;
	}

	public void setFile11ContentType(String file11ContentType) {
		this.file11ContentType = file11ContentType;
	}

	public File getFile12() {
		return file12;
	}

	public void setFile12(File file12) {
		this.file12 = file12;
	}

	public String getFile12ContentType() {
		return file12ContentType;
	}

	public void setFile12ContentType(String file12ContentType) {
		this.file12ContentType = file12ContentType;
	}
*/
	public MerinfoSearchCondtion getSearchCondition() {
		return searchCondition;
	}

	public void setSearchCondition(MerinfoSearchCondtion searchCondition) {
		this.searchCondition = searchCondition;
	}

	public MerinfoDetail getMerinfoDetail() {
		return merinfoDetail;
	}

	public void setMerinfoDetail(MerinfoDetail merinfoDetail) {
		this.merinfoDetail = merinfoDetail;
	}

	public AuditingItem getAuditing() {
		return auditing;
	}

	public void setAuditing(AuditingItem auditing) {
		this.auditing = auditing;
	}

	public String[] getTransTypes() {
		return transTypes;
	}

	public void setTransTypes(String[] transTypes) {
		this.transTypes = transTypes;
	}

	public List<String> getInitCheckBoxList() {
		return initCheckBoxList;
	}

	public void setInitCheckBoxList(List<String> initCheckBoxList) {
		this.initCheckBoxList = initCheckBoxList;
	}

	public List<TermBean> getTermBeanList() {
		return termBeanList;
	}

	public void setTermBeanList(List<TermBean> termBeanList) {
		this.termBeanList = termBeanList;
	}

	public String getIsDetail() {
		return isDetail;
	}

	public void setIsDetail(String isDetail) {
		this.isDetail = isDetail;
	}

	public List<OrgBean> getOrgList() {
		return orgList;
	}

	public void setOrgList(List<OrgBean> orgList) {
		this.orgList = orgList;
	}

	/*public File getFile13() {
		return file13;
	}

	public void setFile13(File file13) {
		this.file13 = file13;
	}

	public String getFile13ContentType() {
		return file13ContentType;
	}

	public void setFile13ContentType(String file13ContentType) {
		this.file13ContentType = file13ContentType;
	}

	public File getFile14() {
		return file14;
	}

	public void setFile14(File file14) {
		this.file14 = file14;
	}

	public String getFile14ContentType() {
		return file14ContentType;
	}

	public void setFile14ContentType(String file14ContentType) {
		this.file14ContentType = file14ContentType;
	}

	public File getFile15() {
		return file15;
	}

	public void setFile15(File file15) {
		this.file15 = file15;
	}

	public String getFile15ContentType() {
		return file15ContentType;
	}

	public void setFile15ContentType(String file15ContentType) {
		this.file15ContentType = file15ContentType;
	}

	public String getImgUrl() {
		return imgUrl;
	}

	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}*/

	// 打开图片
	@Action(value = "openImg", results = { @Result(location = "/pages/merinfo/merinfoImgShow.jsp") })

	public String openImg() {
		//getRequest().setAttribute("imgUrl", imgUrl);

		return SUCCESS;
	}

	// 打开银行选择框
	@Action(value = "openBankMes", results = { @Result(location = "/pages/merinfo/bankMesChoise.jsp") })
	public String openBankMes() {
		getRequest().setAttribute("bankList", ConfigProperties.getBankListProperties());
		return SUCCESS;
	}

	public String getProvice32() {
		return provice32;
	}

	public void setProvice32(String provice32) {
		this.provice32 = provice32;
	}

	public String getCity32() {
		return city32;
	}

	public void setCity32(String city32) {
		this.city32 = city32;
	}

	public String getMerInfoIdList() {
		return merInfoIdList;
	}

	public void setMerInfoIdList(String merInfoIdList) {
		this.merInfoIdList = merInfoIdList;
	}
	
	public InputStream getZipFile() {
		return zipFile;
	}
	public void setZipFile(InputStream zipFile) {
		this.zipFile = zipFile;
	}
	public String getZipName() {
		String zipName="商户图片"+Constance.formateDate();
		 
		try {
			zipName = new String(zipName.getBytes(),"ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			logger.info("生成图片名称失败了！");
		}
		return  zipName;
	}
	
	public void setZipName(String zipName) {
		this.zipName = zipName;
	}

	public File getExcelFile() {
		return excelFile;
	}

	public void setExcelFile(File excelFile) {
		this.excelFile = excelFile;
	}
	
	public String getDealType() {
		return dealType;
	}

	public void setDealType(String dealType) {
		this.dealType = dealType;
	}

	public String getRejectType() {
		return rejectType;
	}

	public void setRejectType(String rejectType) {
		this.rejectType = rejectType;
	}

	public List<String> getRejectReasons() {
		return rejectReasons;
	}

	public void setRejectReasons(List<String> rejectReasons) {
		this.rejectReasons = rejectReasons;
	}

	public Double getZwPayRate() {
		return zwPayRate;
	}

	public void setZwPayRate(Double zwPayRate) {
		this.zwPayRate = zwPayRate;
	}

	public String getMchtRejectType() {
		return mchtRejectType;
	}

	public void setMchtRejectType(String mchtRejectType) {
		this.mchtRejectType = mchtRejectType;
	}

	public String getSaveMerinfoFlag() {
		return saveMerinfoFlag;
	}

	public void setSaveMerinfoFlag(String saveMerinfoFlag) {
		this.saveMerinfoFlag = saveMerinfoFlag;
	}

	public String getAccountNo() {
		return accountNo;
	}

	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}

	public String getMerCardName() {
		return merCardName;
	}

	public void setMerCardName(String merCardName) {
		this.merCardName = merCardName;
	}

	public String getMerCardId() {
		return merCardId;
	}

	public void setMerCardId(String merCardId) {
		this.merCardId = merCardId;
	}

	public boolean isVerifyInfo() {
		return verifyInfo;
	}

	public void setVerifyInfo(boolean verifyInfo) {
		this.verifyInfo = verifyInfo;
	}

	public String getVerifyFlag() {
		return verifyFlag;
	}

	public void setVerifyFlag(String verifyFlag) {
		this.verifyFlag = verifyFlag;
	}

}